var express = require('express');
var router = express.Router();
var checkLogin =require('../middleware/checkLogin');
var reprint =require('../middleware/reprint');

module.exports = router;

//转载
router.get('/:username/:post_id',checkLogin,reprint,function(req,res){
 var err=res.reprintResult.err;
 if (err) {
  if (err.yet) {//提示已经转载过该文章
   req.flash('error', '您已经转载过该文章，访问：http://' + req.headers.host + '/article/' + err.yet.username + '/' + err.yet.reprint_post_id);
  } else {
   req.flash('error', '转载失败');
  }
  return res.redirect('back');
 }
 req.flash('success', '转载成功');
 res.redirect('/article/' + req.params.username + '/' + res.reprintResult.reprint._id);
});
